package edu.mse.camel.client.posterboard.ui.commands;

import org.eclipse.gef.commands.Command;

import edu.mse.camel.client.posterboard.posterboard.PBDiagram;
import edu.mse.camel.client.posterboard.posterboard.Posterboard;

public class PBDiagramDeleteCommand extends AbstractPosterboardCommand {

	private Posterboard parent;
	private PBDiagram child;
	private boolean wasRemoved;
	
	public PBDiagramDeleteCommand(Posterboard parent, PBDiagram child) {
		this.parent = parent;
		this.child = child;
		this.wasRemoved = false;
	}

	@Override
	public boolean canExecute() {
		return true;
	}

	@Override
	public boolean canUndo() {
		return wasRemoved;
	}

	@Override
	public void execute() {
		redo();
	}

	@Override
	public void redo() {
		parent.getDiagrams().remove(child);
		wasRemoved = true;
	}

	@Override
	public void undo() {
		parent.getDiagrams().add(child);
	}

}
